home *** CD-ROM | disk | FTP | other *** search
/ Programming a Multiplayer FPS in DirectX / Programming a Multiplayer FPS in DirectX (Companion CD).iso / DirectX / dxsdk_oct2004.exe / dxsdk.exe / Utilities / MView / shownormals.fx < prev    next >
Encoding:
Text File  |  2004-09-27  |  7.3 KB  |  294 lines

  1. //
  2. // Standard texture effect
  3. // Copyright {c} 2000 Microsoft Corporation. All rights reserved.
  4. //
  5.  
  6. vector vClr;   // color 
  7.  
  8. vector vScl;
  9.  
  10. matrix mWld;    // World
  11. matrix mTot;     // Total 
  12.  
  13. matrix mWd1;     
  14. matrix mWd2;     
  15. matrix mWd3;     
  16. matrix mWd4;     
  17. matrix mWd5;     
  18. matrix mWd6;     
  19. matrix mWd7;     
  20. matrix mWd8;     
  21. matrix mWd9;     
  22. matrix mWd10;     
  23. matrix mWd11;     
  24. matrix mWd12;     
  25. matrix mWd13;     
  26. matrix mWd14;     
  27. matrix mWd15;     
  28. matrix mWd16;     
  29. matrix mWd17;     
  30. matrix mWd18;     
  31. matrix mWd19;     
  32. matrix mWd20;     
  33. matrix mWd21;     
  34. matrix mWd22;     
  35. matrix mWd23;     
  36. matrix mWd24;     
  37. matrix mWd25;     
  38. matrix mWd26;     
  39. matrix mWd27;     
  40. matrix mWd28;     
  41.  
  42. float4x3 mWorlds[28];
  43.  
  44. Vertexshader vNonIndexed = 
  45.     decl
  46.     {
  47.                 stream 0;
  48.  
  49.                 float v0[3];
  50.                 float v1[4];
  51.                 float v3[3];
  52.     }
  53.     asm
  54.     {
  55.     vs.1.1
  56.     
  57.     dcl_position v0;
  58.     dcl_blendweight v1;
  59.     dcl_normal v3;
  60.  
  61.     m4x3 r0.xyz,v0,c0
  62.     m4x3 r1.xyz,v0,c4
  63.     m4x3 r2.xyz,v0,c8
  64.     m4x3 r3.xyz,v0,c12
  65.  
  66.     mul r0.xyz,r0.xyz,v1.xxxx
  67.     mad r0.xyz,r1.xyz,v1.yyyy,r0
  68.     mad r0.xyz,r2.xyz,v1.zzzz,r0
  69.     mad r0.xyz,r3.xyz,v1.wwww,r0
  70.  
  71.     m3x3 r4.xyz,v3,c0
  72.     m3x3 r5.xyz,v3,c4
  73.     m3x3 r6.xyz,v3,c8
  74.     m3x3 r7.xyz,v3,c12
  75.  
  76.     mul r4.xyz,r4.xyz,v1.xxxx
  77.     mad r4.xyz,r5.xyz,v1.yyyy,r4
  78.     mad r4.xyz,r6.xyz,v1.zzzz,r4
  79.     mad r4.xyz,r7.xyz,v1.wwww,r4
  80.  
  81.     mad r0.xyz,r4.xyz,c21.xxxx,r0
  82.  
  83.     mov r0.w,c20.x
  84.     m4x4 oPos,r0,c16
  85.  
  86.     mov oD0,c22
  87.     };
  88.  
  89. struct VS_INPUT_NONINDEXED
  90. {
  91.     float4 Position : POSITION;
  92.     float4 Weights : BLENDWEIGHT;
  93.     float3 Normal: NORMAL;
  94. };
  95.  
  96. struct VS_INPUT_INDEXED
  97. {
  98.     float4 Position : POSITION;
  99.     float4 Weights : BLENDWEIGHT;
  100.     float4 BlendIndices : BLENDINDICES;
  101.     float3 Normal: NORMAL;
  102. };
  103.  
  104. struct VS_OUTPUT
  105. {
  106.     float4 Position : POSITION;
  107.     float4 Color : COLOR;
  108. };
  109.  
  110.  
  111.  
  112. VS_OUTPUT NonIndexed(VS_INPUT_NONINDEXED Input)
  113. {
  114.     float3 Position;
  115.     float3 Normal;
  116.     VS_OUTPUT Output;
  117.  
  118.  
  119.     Position = mul(Input.Position, (float4x3)mWd1) * Input.Weights.xxx;
  120.     Normal = mul(Input.Normal, (float3x3)mWd1) * Input.Weights.xxx;
  121.  
  122.     Position += mul(Input.Position, (float4x3)mWd2) * Input.Weights.yyy;
  123.     Normal += mul(Input.Normal, (float3x3)mWd2) * Input.Weights.yyy;
  124.  
  125.     Position += mul(Input.Position, (float4x3)mWd3) * Input.Weights.zzz;
  126.     Normal += mul(Input.Normal, (float3x3)mWd3) * Input.Weights.zzz;
  127.  
  128.     Position += mul(Input.Position, (float4x3)mWd4) * Input.Weights.www;
  129.     Normal += mul(Input.Normal, (float3x3)mWd4) * Input.Weights.www;
  130.  
  131.     Position += Normal * vScl.xxx;
  132.  
  133.     Output.Color = vClr;
  134.     Output.Position = mul(float4(Position, 1.0), mTot);
  135.  
  136.     return Output;    
  137. }
  138.  
  139. #if 1
  140. VS_OUTPUT Indexed(VS_INPUT_INDEXED Input)
  141. {
  142.     float3 Position;
  143.     float3 Normal;
  144.     VS_OUTPUT Output;
  145.     float4 BlendIndices;
  146.  
  147.     BlendIndices = D3DCOLORtoUBYTE4(Input.BlendIndices);
  148.  
  149.     Position = mul(Input.Position, (float4x3)mWorlds[BlendIndices.x]) * Input.Weights.xxx;
  150.     Position += mul(Input.Position, (float4x3)mWorlds[BlendIndices.y]) * Input.Weights.yyy;
  151.     Position += mul(Input.Position, (float4x3)mWorlds[BlendIndices.z]) * Input.Weights.zzz;
  152.     Position += mul(Input.Position, (float4x3)mWorlds[BlendIndices.w]) * Input.Weights.www;
  153.  
  154.     Normal = mul(Input.Normal, (float3x3)mWorlds[BlendIndices.x]) * Input.Weights.xxx;
  155.     Normal += mul(Input.Normal, (float3x3)mWorlds[BlendIndices.y]) * Input.Weights.yyy;
  156.     Normal += mul(Input.Normal, (float3x3)mWorlds[BlendIndices.z]) * Input.Weights.zzz;
  157.     Normal += mul(Input.Normal, (float3x3)mWorlds[BlendIndices.w]) * Input.Weights.www;
  158.  
  159.     Position += Normal * vScl.xxx;
  160.  
  161.     Output.Color = vClr;
  162.     Output.Position = mul(float4(Position, 1.0), mTot);
  163.  
  164.     return Output;    
  165. }
  166. #endif
  167.  
  168. Vertexshader vIndexed = 
  169.     decl
  170.     {
  171.                 stream 0;
  172.  
  173.                 float v0[3];
  174.                 float v1[4];
  175.                 d3dcolor v2[1];
  176.                 float v3[3];
  177.     }
  178.     asm
  179.     {
  180.     vs.1.1
  181.  
  182.     dcl_position v0;
  183.     dcl_blendweight v1;
  184.     dcl_blendindices v2;
  185.     dcl_normal v3;
  186.  
  187.     // Compensate for lack of UBYTE4 on Geforce3
  188.     mul r8,v2.zyxw,c4.wwww
  189.     
  190.     mov a0.x,r8.x
  191.     m4x3 r0.xyz,v0,c[a0.x + 9]
  192.     m3x3 r4.xyz,v3,c[a0.x + 9]
  193.     mov a0.x,r8.y
  194.     m4x3 r1.xyz,v0,c[a0.x + 9]
  195.     m3x3 r5.xyz,v3,c[a0.x + 9]
  196.     mov a0.x,r8.z
  197.     m4x3 r2.xyz,v0,c[a0.x + 9]
  198.     m3x3 r6.xyz,v3,c[a0.x + 9]
  199.     mov a0.x,r8.w
  200.     m4x3 r3.xyz,v0,c[a0.x + 9]
  201.     m3x3 r7.xyz,v3,c[a0.x + 9]
  202.  
  203.     mul r0.xyz,r0.xyz,v1.xxxx
  204.     mad r0.xyz,r1.xyz,v1.yyyy,r0
  205.     mad r0.xyz,r2.xyz,v1.zzzz,r0
  206.     mad r0.xyz,r3.xyz,v1.wwww,r0
  207.  
  208.     mul r4.xyz,r4.xyz,v1.xxxx
  209.     mad r4.xyz,r5.xyz,v1.yyyy,r4
  210.     mad r4.xyz,r6.xyz,v1.zzzz,r4
  211.     mad r4.xyz,r7.xyz,v1.wwww,r4
  212.  
  213.     mad r0.xyz,r4.xyz,c6.xxxx,r0
  214.  
  215.     mov r0.w,c4.x
  216.     m4x4 oPos,r0,c0
  217.  
  218.     mov oD0,c5
  219.     };
  220.  
  221. technique NonIndexed
  222. {
  223.     pass P0
  224.     {
  225.         ColorVertex = FALSE;
  226.  
  227.         ColorOp[0]   = Disable;
  228.         AlphaOp[0]   = Disable;
  229.  
  230.         //VertexShader = <vNonIndexed>;
  231.         VertexShader = compile vs_1_1 NonIndexed();
  232. #if 0
  233.         VertexShaderConstant[0] = <mWd1>;
  234.         VertexShaderConstant[4] = <mWd2>;
  235.         VertexShaderConstant[8] = <mWd3>;
  236.         VertexShaderConstant[12] = <mWd4>;
  237.         VertexShaderConstant[16] = <mTot>;
  238.         VertexShaderConstant[20] = {1.0f, 0.0f, 0.0f, 0.0f};
  239.         VertexShaderConstant[21] = <vScl>;
  240.         VertexShaderConstant[22] = <vClr>;
  241. #endif
  242.     }
  243. }
  244.  
  245. technique Indexed
  246. {
  247.     pass P0
  248.     {
  249.         ColorVertex = FALSE;
  250.  
  251.         ColorOp[0]   = Disable;
  252.         AlphaOp[0]   = Disable;
  253.  
  254. #if 0
  255.         VertexShader = <vIndexed>;
  256.  
  257.         VertexShaderConstant[0] = <mTot>;
  258.         VertexShaderConstant[4] = { 1.0f, 0.0f, 0.0f, 765.01f };
  259.         VertexShaderConstant[5] = <vClr>;
  260.         VertexShaderConstant[6] = <vScl>;
  261.  
  262.         VertexShaderConstant3[9] = <mWd1>;
  263.         VertexShaderConstant3[12] = <mWd2>;
  264.         VertexShaderConstant3[15] = <mWd3>;
  265.         VertexShaderConstant3[18] = <mWd4>;
  266.         VertexShaderConstant3[21] = <mWd5>;
  267.         VertexShaderConstant3[24] = <mWd6>;
  268.         VertexShaderConstant3[27] = <mWd7>;
  269.         VertexShaderConstant3[30] = <mWd8>;
  270.         VertexShaderConstant3[33] = <mWd9>;
  271.         VertexShaderConstant3[36] = <mWd10>;
  272.         VertexShaderConstant3[39] = <mWd11>;
  273.         VertexShaderConstant3[42] = <mWd12>;
  274.         VertexShaderConstant3[45] = <mWd13>;
  275.         VertexShaderConstant3[48] = <mWd14>;
  276.         VertexShaderConstant3[51] = <mWd15>;
  277.         VertexShaderConstant3[54] = <mWd16>;
  278.         VertexShaderConstant3[57] = <mWd17>;
  279.         VertexShaderConstant3[60] = <mWd18>;
  280.         VertexShaderConstant3[63] = <mWd19>;
  281.         VertexShaderConstant3[66] = <mWd20>;
  282.         VertexShaderConstant3[69] = <mWd21>;
  283.         VertexShaderConstant3[72] = <mWd22>;
  284.         VertexShaderConstant3[75] = <mWd23>;
  285.         VertexShaderConstant3[78] = <mWd24>;
  286.         VertexShaderConstant3[81] = <mWd25>;
  287.         VertexShaderConstant3[84] = <mWd26>;
  288.         VertexShaderConstant3[87] = <mWd27>;
  289.         VertexShaderConstant3[90] = <mWd28>;
  290. #else
  291.         VertexShader = compile vs_1_1 Indexed();
  292. #endif
  293.     }
  294. }